package com.maimao.model.goods;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2020/11/27 11:39 下午
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("mm_goods_sku")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GoodsSku implements Serializable {
    private static final long serialVersionUID = -6224160059241635818L;

    /**
     * 序列化到前端变为字符串防止精度丢失
     */
    @TableId(type = IdType.ASSIGN_ID)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    @TableField("goods_id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long goodsId;

    /**
     * sku名称
     */
    @NotBlank(message = "请填写sku名称")
    @TableField("`name`")
    private String name;


    @TableField("pictures")
    private String pictures;

    /**
     * 显示在展示页的图片索引
     */
    @NotNull(message = "请选择展示页的图片项")
    @TableField("show_index")
    private Integer showIndex;

    /**
     * sku 规格json
     */
    @NotBlank(message = "请选择销售规格")
    private String spec;

    @TableField(exist = false)
    private String specStr;

    /**
     * 规格值在goods表中sku规格中的下标位置 用下划线分隔
     */
    @NotBlank(message = "规格索引不能为空")
    @TableField("spec_indexes")
    private String specIndexes;

    @NotNull(message = "请填写宝贝价格")
    @Min(value = 0, message = "价格不能低于0")
    private BigDecimal price;

    /**
     * 秒杀价格
     */
    @TableField("kill_price")
    private BigDecimal killPrice;

    /**
     * 是否秒杀中
     */
    @TableField("sec_kill")
    private Integer secKill;

    @NotNull(message = "请填写宝贝库存")
    @Min(value = 0, message = "库存不能低于0")
    private Integer stock;

    private Integer valid;

    /**
     * 赠送积分 （积分规则 100元--> 10积分  100积分 -->抵扣1元）
     */
    @NotNull(message = "请填写宝宝积分")
    @Min(value = 0, message = "积分不能低于0")
    private Integer integral;

    /**
     * 是否参与赠送积分
     */
    @NotNull(message = "请填写是否参与积分")
    @TableField("give_integral")
    private Boolean giveIntegral;

    @TableField("create_time")
    private LocalDateTime createTime;

    @TableField("kill_start_time")
    private LocalDateTime killStartTime;

    @TableField("kill_end_time")
    private LocalDateTime killEndTime;

    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 上传时传入的图片列表
     */
    @NotNull(message = "请上传宝贝图片")
    @Size(min = 1, max = 5, message = "图片个数应在1到5个内")
    @TableField(exist = false)
    private List<String> pictureList;

    @Override
    public String toString() {
        return "GoodsSku{" +
                "id=" + id +
                ", goodsId=" + goodsId +
                ", name='" + name + '\'' +
                ", pictures='" + pictures + '\'' +
                ", showIndex=" + showIndex +
                ", spec='" + spec + '\'' +
                ", specIndexes='" + specIndexes + '\'' +
                ", price=" + price +
                ", killPrice=" + killPrice +
                ", secKill=" + secKill +
                ", stock=" + stock +
                ", valid=" + valid +
                ", integral=" + integral +
                ", giveIntegral=" + giveIntegral +
                ", createTime=" + createTime +
                ", killStartTime=" + killStartTime +
                ", killEndTime=" + killEndTime +
                ", updateTime=" + updateTime +
                ", pictureList=" + pictureList +
                '}';
    }
}
